<template>
<div>
   <div class="g_top_box">
		<div class="g_right_box"></div> 
		<div class="g_left_box"><h4>管理员信息</h4></div>
	</div>
	<div class="g_content_box">

		<Form :model="info" label-position="left" :label-width="100">
			<FormItem label="名称">
				<Input v-model="info.name" style="width:200px;"></Input>
			</FormItem>
			<FormItem label="描述">
				<Input v-model="info.info" type="textarea" style="width:500px;"></Input>
			</FormItem>
			<FormItem label="权限设置">
				<div v-for="(val,index) in priv_list">	
					<check_group :data="val" :ref="'check_'+index"></check_group>
				</div>
			</FormItem>
			
			<FormItem>
				<Button type="primary" @click="save">提交</Button>
			</FormItem>
		</Form>

	</div>
</div>
</template>

<script>
import Wcore from '@/libs/common';
import check_group from './check_group';

export default {
    name: 'admin_info',
    data (){
        return {
            info:{
				name:'',
				info:'',
				privs:'',
			},
			priv_list:[]
        };
    },
	created(){
		this.load_priv();
	},
    components: {
       check_group
    },
	methods:{
		load_priv(){
			var self = this;
			
			Whttp.load('System/Role/get_priv_list',{},function(result){
				self.priv_list = result;
			});
		},
		save(){
			var self = this;
			
			
			var priv_arr = [];

			for(var i=0;i<this.priv_list.length;i++){
				var ref = 'check_'+i;
				var comm = this.$refs[ref][0];
				
				var ls_arr = comm.get_sel_value();
				for(var k=0;k<ls_arr.length;k++){
					priv_arr.push(ls_arr[k]);
				}
			}

			var postdata = {
				name:this.info.name,
				info:this.info.info,
				privs:priv_arr.join(',')
			};
			Whttp.load('System/Role/save',postdata,function(result){
				self.$Message.info('添加成功');
				self.$router.back();
			});
		},
		
	}
};
</script>